--drop trigger insert_guard_asist on guardia;
--drop function llenarAsist();

create function llenarAsist()
returns trigger as $llenarAsist$
begin
insert into asistencia(ci,id_guardia,nombre_sede)
select pg.ci, NEW.id_guardia, NEW.sede
from pertenece_grupo pg
where
pg.id_grupo = NEW.id_grupo and
pg.sede = NEW.sede;
return null;
end;
$llenarAsist$ language plpgsql;

create trigger insert_guard_asist
after insert on guardia
for each row execute procedure llenarAsist();

create function boolEsp(boolean)
returns varchar as $boolEsp$
declare
valor alias for $1;
begin
if (valor) then
	return 'X';
else
	return '';
end if;
end;
$boolEsp$ language 'plpgsql';
